import 'package:flutter/material.dart';

class NavigationIconView{
  final String _title;
  final Widget _icon;
  final Widget _activeIcon;
  final BottomNavigationBarItem item;

  NavigationIconView({Key key,String title,Widget icon,Widget activeIcon}):
    _title = title,
    _icon = icon,
    _activeIcon = activeIcon,
    item = new BottomNavigationBarItem(
      title: new Text(title),
      icon: icon,
      activeIcon: activeIcon,
      backgroundColor: Colors.white
    );
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {

  List<NavigationIconView> _navigationViews;

  @override
    void initState() {
      // TODO: implement initState
      super.initState();
      _navigationViews = [
        NavigationIconView(
          title: "微信",
          icon: Icon(Icons.chat),
          activeIcon: Icon(Icons.change_history)
        ),
        NavigationIconView(
          title: "通讯录",
          icon: Icon(Icons.contacts),
          activeIcon: Icon(Icons.contact_phone)
        ),
        NavigationIconView(
          title: "发现",
          icon: Icon(Icons.find_replace),
          activeIcon: Icon(Icons.find_in_page)
        ),
        NavigationIconView(
          title: "我",
          icon: Icon(Icons.people),
          activeIcon: Icon(Icons.people_outline)
        )
      ];
    }
  @override
  Widget build(BuildContext context) {
    final BottomNavigationBar botNavBar = new BottomNavigationBar(
      items: _navigationViews.map((NavigationIconView navigationView){
        return navigationView.item;
      }).toList(),
      currentIndex: 0,
      type: BottomNavigationBarType.fixed,
      onTap: (int index){
        print("点击了 index $index tab项");
      },
    );
    return new Scaffold(
      appBar: AppBar(
        title: Text("微信"),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.search),
            onPressed:() {
              print("点击了搜索按钮");
            },
          ),
          IconButton(
            icon: Icon(Icons.add),
            onPressed: (){
              print("点击了加号图标");
            },
          )
        ],
        // backgroundColor: Color(0xff303030),
      ),
      body: Container(
        color: Colors.red,
      ),
      bottomNavigationBar: botNavBar,
    );
  }
}